package club.banyuan;

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

class MyLinkedListTest {

  @Test
  void test() {
    var list = new MyLinkedList<Integer>();
    System.out.println(list);
    Assertions.assertFalse(list.add(10, 1));
    list.add(10, 0);
    list.add(20, 1);
    list.add(30, 2);
    list.add(25, 2);
    list.add(5, 0);
    System.out.println(list);
    Assertions.assertEquals(25, list.remove(3));
    System.out.println(list);
    Assertions.assertEquals(5, list.remove(0));
    Assertions.assertEquals(30, list.remove(list.size() - 1));
    System.out.println(list);
  }

  @Test
  void iterate() {
    var list = new MyLinkedList<Integer>();
    for (int i = 0; i < 10; i++) {
      list.addAtHead(i);
    }
    System.out.println(list);
    int out = 0;
    while (!list.isEmpty()) {
      Assertions.assertEquals(out++, list.removeTail());
      System.out.println(list);
    }
  }
}
